#!/bin/bash

if [ -f /etc/issue ]; then
PRE=/opt/data/
EXEC=$PRE/proj/apps/mongodb/bin/mongod
else
## mac
PRE=/Volumes/MacintoshHD/Users/jmd/proj
EXEC=$PRE/app/mongodb/bin/mongod
fi

export PATH=$PATH:$EXEC/../

cnt=`ps ax | grep -v grep | grep $EXEC | wc -l`
if [ $cnt -gt 0 ]; then
    echo -e "mongod has execute"
    exit
fi

DIR=--directoryperdb
#BACK=--fork
DBPATHCMD=--dbpath
#DBPATHCMD=--repairpath
DBPATH=$PRE/todocker/data/db
LOGCMD=--logpath
LOGPATH=$PRE/todocker/logs/mongod.log
#LOGAPPEND=--logappend
LOGSYS=--syslog
OTHER=--cpu

if [ "$1" == "m" ];then
STYLE=--master
elif [ "$1" == "s" ]; then
STYLE=--slave
fi

ARGS="$DBPATHCMD $DBPATH $LOGCMD $LOGPATH $LOGAPPEND $DIR $OTHER $BACK $STYLE"

echo "execute: $EXEC $ARGS"
$EXEC $ARGS
